package com.snc.controller.monitor;


import com.snc.exception.BusinessException;
import com.snc.exception.ParameterException;
import com.snc.plugin.Result;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;



/**
 * 通过 ResponseBody  注解拦截Controller异常
 * @author  shenyuting
 * 2015年11月20日 上午9:33:30
 */
@Component
@Aspect
public class ControllerMonitor {
	public static final Logger logger=LoggerFactory.getLogger(ControllerMonitor.class);
	
	/**
	 * ajax请求json异常
	 * @param call
	 * @return
	 * @throws Throwable
	 */
	@Around("execution(* com.snc.controller.app.*.*(..)) && @annotation(org.springframework.web.bind.annotation.ResponseBody)")
	public Object executeJson(ProceedingJoinPoint call) throws Throwable {
		Object obj=null;
		try {
			obj = call.proceed();
		} catch (Exception ex) {
			String message=ex.getMessage();
			logger.error(message,ex);
			if(ex instanceof Exception){
				return Result.Fail(ex.getMessage());
			}
		}
		return obj;
	}
}
